package services

import (
	"longmen/server/config/global"
	"longmen/server/pkg/db/mysql/models/models_report"
	"time"

	"gorm.io/gorm"
)

func (s *Service) TransitStat() {
	today := time.Now().Format("2006-01-02")

	rows := global.Report().Model(&models_report.Transit{}).Where("date=?", today).Update("open", gorm.Expr("open+1")).RowsAffected

	if rows == 0 {
		global.Report().Model(&models_report.Transit{}).Create(&models_report.Transit{
			Date:  time.Now(),
			Open:  1,
			Click: 0,
		})
	}
}

func (s *Service) TransiOpenStat() error {
	today := time.Now().Format("2006-01-02")
	global.Report().Model(&models_report.Transit{}).Where("date=?", today).Update("click", gorm.Expr("click+1"))
	return nil
}
